package com.leji.song.myOrder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.leji.song.R;
import com.leji.song.myOrder.model.DS_OrderGoods;

import java.util.List;

/**
 * Created by colin.ding on 2014/7/2.
 */
public class OrderDetailListAdapter extends BaseAdapter {
    protected ListItemView listItemView;
    protected LayoutInflater listContainer;
    protected Context context;
    protected List<DS_OrderGoods> orderDetailList;

    public OrderDetailListAdapter(){};

    public OrderDetailListAdapter(Context context, List<DS_OrderGoods> orderDetailList){
        this.context = context;
        this.orderDetailList = orderDetailList;

        listContainer = LayoutInflater.from(context);

    }

    protected static class ListItemView{
        public TextView name;
        public TextView price;
        public TextView number;


    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return orderDetailList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 自定义视图
        listItemView = new ListItemView();
        // 获取list_item布局文件的视图
        if (convertView == null) {
            convertView = listContainer.inflate(R.layout.my_order_detail_list_adapter, null);
            // 获取控件对象
            listItemView.name = (TextView) convertView
                    .findViewById(R.id.name);

            listItemView.price = (TextView) convertView
                    .findViewById(R.id.price);

            listItemView.number = (TextView) convertView
                    .findViewById(R.id.number);

            // 设置控件集到convertView
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }

        listItemView.name.setText(orderDetailList.get(position).getName());
        listItemView.price.setText("￥" + orderDetailList.get(position).getPrice());
        listItemView.number.setText(orderDetailList.get(position).getAmount() + "份× ");


        return convertView;
    }

    class MyClickListener implements View.OnClickListener {
        private int position;

        public MyClickListener(int position){
            this.position = position;
        }
        @Override
        public void onClick(View v) {

            //dgltodo
        }

    }
}
